
# -*- coding: utf-8 -*- 
import wx 
import math 
# 导入gui工具生成的python文件 
import search_frame
import red_map
import mdpin_db




global glob_com_port,glob_com_baudrate

class SearchFrame(search_frame.SearchFrame): 
    def __init__(self,parent):
        search_frame.SearchFrame.__init__(self,parent) 
    
    def set_textCtrl( self,time, syslog,name,addr,info,other ):# 窗口信息显示
        textboxstr="%-25.25s %-20.20s %-20.20s %-20.20s %-25.25s %-10.10s\n"%(time,syslog,name,addr,info,other)
        a1=len(syslog)/20
        a2=len(name)/20
        a3=len(addr)/20
        a4=len(info)/25
        a5=len(other)/10
        big=max(a1,a2,a3,a4,a5)
        if big<1:           
            self.m_textCtrl5.AppendText(textboxstr)
        else:
            textboxstr2=textboxstr
            print textboxstr2
            self.m_textCtrl5.AppendText(textboxstr2)
            cell=int(math.ceil(big))
            for i in range(1,cell+1):
                textboxstr="%-20.20s %-20.20s %-20.20s %-25.25s %-10.10s\n"%(syslog[20*i:],name[20*i:],addr[20*i:],info[25*i:],other[10*i:])
                textboxstr3="%-26s"%" "+textboxstr
                self.m_textCtrl5.AppendText(textboxstr3)
                print textboxstr3
        return 0

    def on_btnSearch(self,event):   # 查询
        begin_time=self.m_datePicker2.GetValue().Format('%Y-%m-%d')+' 00:00:00'
        end_time=self.m_datePicker3.GetValue().Format('%Y-%m-%d')+' 23:59:59'
        key_name=self.m_textCtrl8.GetValue()
        rows=mdpin_db.db_find('histry',begin_time,end_time,key_name)
        self.m_textCtrl5.AppendText("%-30s----------开始查询："%(" "))
        self.m_textCtrl5.AppendText("%s-----------%-10s\n"%(key_name," "))
        for row in rows:  
           self.set_textCtrl(row['time'],row['syslog'],row['name'],row['addr'],row['info'],'')  
        self.m_textCtrl5.AppendText("%-30s----------查询结束----------%-30s\n"%(" "," "))
        self.m_textCtrl5.AppendText("%-30s--------共计:%d个结果-------%-24s\n"%(" ",len(rows)," "))